import request from '@/utils/request'
import {
  getToken
} from '@/utils/auth'
import {
  param
} from '@/utils/index'

// 分页
export function pagingPurchaseOrder(query) {
  return request({
    url: '/warehouse/purchaseOrder/paging',
    method: 'get',
    params: query
  })
}

// 统计采购订单
export function statPurchaseOrder(query) {
  return request({
    url: '/warehouse/purchaseOrder/statPurchaseOrder',
    method: 'get',
    params: query
  })
}

// 根据主键获取采购订单
export function getPurchaseOrder(purchaseOrderId) {
  return request({
    url: '/warehouse/purchaseOrder/get',
    method: 'get',
    params: {
      purchaseOrderId
    }
  })
}

// 根据采购订单号 + 仓库商品ID获取采购订单商品
export function getOrderGoods(query) {
  return request({
    url: '/warehouse/purchaseOrder/getOrderGoods',
    method: 'get',
    params: query
  })
}

// 保存
export function savePurchaseOrder(data) {
  return request({
    url: '/warehouse/purchaseOrder/save',
    method: 'post',
    data: data
  })
}

// 保存发票类型
export function saveInvoiceType(data) {
  return request({
    url: '/warehouse/purchaseOrder/saveInvoiceType',
    method: 'post',
    data: data
  })
}

// 采购单拷贝处理
export function doCopy(purchaseOrderId) {
  return request({
    url: '/warehouse/purchaseOrder/doCopy',
    method: 'post',
    data: {
      purchaseOrderId
    }
  })
}

// 采购单提交处理
export function doSubmit(purchaseOrderId) {
  return request({
    url: '/warehouse/purchaseOrder/doSubmit',
    method: 'post',
    data: {
      purchaseOrderId
    }
  })
}

// 采购单批量提交处理
export function batchSubmit(purchaseOrderIds) {
  return request({
    url: '/warehouse/purchaseOrder/batchSubmit',
    method: 'post',
    data: {
      purchaseOrderIds
    }
  })
}

// 采购单撤销处理
export function doRevoke(purchaseOrderId) {
  return request({
    url: '/warehouse/purchaseOrder/doRevoke',
    method: 'post',
    data: {
      purchaseOrderId
    }
  })
}

// 采购单批量提交处理
export function batchRevoke(purchaseOrderIds) {
  return request({
    url: '/warehouse/purchaseOrder/batchRevoke',
    method: 'post',
    data: {
      purchaseOrderIds
    }
  })
}

// 采购单审核处理
export function doAudit(data) {
  return request({
    url: '/warehouse/purchaseOrder/doAudit',
    method: 'post',
    data: data
  })
}

// 采购单批量审核处理
export function batchAudit(data) {
  return request({
    url: '/warehouse/purchaseOrder/batchAudit',
    method: 'post',
    data: data
  })
}

// 采购单导出处理（企业系统端）
export function doExportByEnterprise(query) {
  return process.env.BASE_API + '/warehouse/purchaseOrder/doExportByEnterprise?' + param(query) + '&accessToken=' +
    getToken()
}

// 采购单导出处理（仓库子系统端）
export function doExportByWarehouse(query) {
  return process.env.BASE_API + '/warehouse/purchaseOrder/doExportByWarehouse?' + param(query) + '&accessToken=' +
    getToken()
}

// 采购单删除处理
export function deletePurchaseOrder(purchaseOrderId) {
  return request({
    url: '/warehouse/purchaseOrder/delete',
    method: 'post',
    data: {
      purchaseOrderId
    }
  })
}

// 采购单批量删除处理
export function batchDelete(purchaseOrderIds) {
  return request({
    url: '/warehouse/purchaseOrder/batchDelete',
    method: 'post',
    data: {
      purchaseOrderIds
    }
  })
}
// 根据主键id，更新采购单状态
// purchaseOrderIds：主键id集合
// purchaseOrderStatus：状态  -2：已终止 -1：审核未通过 0：待提交 1：待审核 2：待入库 3：部分入库 4：已完成（备注：退货单的时候 2：待出库 3：部分出库）
// remark：备注，如果是审核意见，也传这个过来
export function updateBatchPurchaseOrderStatusByIds(purchaseOrderIds, purchaseOrderStatus, remark) {
  var data = {
    purchaseOrderIds: purchaseOrderIds,
    purchaseOrderStatus: purchaseOrderStatus,
    remark: remark
  }
  return request({
    url: '/warehouse/purchaseOrder/updateBatchPurchaseOrderStatus',
    method: 'post',
    data: data
  })
}
